home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / COPYA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  659 b   |  36 lines

  1. /* COPYA.C - COPY A FILE WITH GETC/PUTC  */
  2. #include "stdio.h"
  3.  
  4. main(argc,argv)
  5.     int argc  ;
  6.     char *argv[]  ;
  7.     {
  8.      FILE  *in ,
  9.            *out ;
  10.      int c    ;
  11.      long n  ;
  12.  
  13.      if( argc < 3 )
  14.           { printf(" USAGE - copy2 input-file output-file \n");
  15.            exit(1);
  16.           }
  17.  
  18.     in  = fopen(argv[1],"r");
  19.     out = fopen(argv[2],"w");
  20.     if( (in == NULL) || (out == NULL) )
  21.           { printf(" Can't open a file");
  22.         exit(0) ;
  23.           }
  24.  
  25.      n  = 0L  ;
  26.      c  = getc(in)    ;
  27.      while( c != EOF )
  28.           { n = n + 1  ;
  29.         putc(c,out);
  30.         c = getc(in)  ;
  31.           }  ;
  32.      fclose(in) ;
  33.      fclose(out);
  34.      printf(" %1d  characters copied",n)  ;
  35.     }
  36.